
package com.wangzhen.spring.inject;

import com.wangzhen.spring.inject.holder.UserHolder;
import com.wangzhen.spring.ioc.dependcy.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Collection;

public class DependencyResoulationDemo {

    @Autowired
    private User user;

    @Autowired
    private Collection<User> users;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(DependencyResoulationDemo.class);

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
        // 加载XML配置，解析生成BeanDefinition
        String xmlLoaction = "classpath:/META-INF/dependcy-setter-context.xml";
        reader.loadBeanDefinitions(xmlLoaction);
        context.refresh();


        DependencyResoulationDemo bean = context.getBean(DependencyResoulationDemo.class);
        System.out.println(bean.user);
        System.out.println(bean.users);

        System.out.println(context.getBean("userHolder2"));
        System.out.println(context.getBean("userHolder"));
    }
}
